<?php

class Colors extends CActiveRecord
{

	public $color;
    public $r, $g, $b;
    public $delete;

    public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	public function tableName()
	{
		return '{{colors}}';
	}

	public function rules()
	{
		return array(
			array('color', 'required'),
			array('r, g, b', 'numerical', 'integerOnly'=>true),
			array('color', 'length', 'max'=>28),
			array('id', 'safe', 'on'=>'search'),
		);
	}

	public function attributeLabels()
	{
		return array(
			'id' => 'Id',
			'color' => 'Название',
			'r' => 'R',
			'g' => 'G',
			'b' => 'B',
		);
	}

	public function search()
	{
		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('color',$this->color,true);
		$criteria->compare('r',$this->r);
		$criteria->compare('g',$this->g);
		$criteria->compare('b',$this->b);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

    public function getItemsToUpdate()
    {
        return self::model()->findAll();
    }
}